<?php

function my_memory_get_usage($msg = '')
{
	static $last = 0;
	$c = memory_get_usage();
	$add = $c - $last;
	$add = ($add >= 0) ? '[+'.$add.']' : '['.$add.']';
	echo $c.' '.$add."\t\t: $msg\r\n";
	$last = $c;
}

#<editor-fold defaultstate="collapsed" desc="start">
ini_set('max_execution_time', 10);
include 'core/core.php';
#</editor-fold>

CCore::Using('base.iostream');






class CCC
{
	function Help()
	{
		$test = file_get_contents('examples/eml/simple with attachment.eml');
		my_memory_get_usage('read in $test');

		$h = new CCoreBaseIoStream();
		my_memory_get_usage('new CCoreBaseIoStream();');

		$h->InitByData($test);
		my_memory_get_usage('$h->InitByData($test);;');

		unset($test);
		my_memory_get_usage('unset($test);');

		$r = $h->GetHandle();
		my_memory_get_usage('$r = $h->GetHandle();');
		
		echo fgets($r, 1024);
		my_memory_get_usage('fgets($r, 1024);');
		echo fgets($r, 1024);
		my_memory_get_usage('fgets($r, 1024);');
		echo fgets($r, 1024);
		my_memory_get_usage('fgets($r, 1024);');
		echo fgets($r, 1024);
		my_memory_get_usage('fgets($r, 1024);');
		echo fgets($r, 1024);
		my_memory_get_usage('fgets($r, 1024);');
		
		fclose($r);
		my_memory_get_usage('fclose($r);');
		
		
		/*
		$test = file_get_contents('examples/eml/simple.eml');
		my_memory_get_usage('read in $test');

		$r = fopen('php://memory', 'a+');
		fwrite($r, $test);

		my_memory_get_usage('fwrite($r, $test);');


		/**
		CCoreBaseStreamWrapper::RegValue('test1', $test);
		my_memory_get_usage('RegValue $test');

		$r = fopen('ccore://test1', 'a+');
		echo fgets($r, 1000);
		fclose($r);

		echo file_get_contents('ccore://test1');
		/**/
	}
}

echo '<pre>';
my_memory_get_usage('start');

CCC::Help();

my_memory_get_usage('end');
